package com.xieke.admin.service.impl;


import com.xieke.admin.mapper.HisTjDjbMapper;
import com.xieke.admin.service.IHisTjDjbService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class HisTjDjbServiceImpl implements IHisTjDjbService {

    @Resource
    private HisTjDjbMapper hisTjDjbMapper;

    @Override
    public List<Map<String, Object>> queryListForJGName() {
        return hisTjDjbMapper.queryListForJGName();
    }

    @Override
    public List<Map<String, Object>> queryListForMedicalDiseases(int limit) {
        return hisTjDjbMapper.queryListForMedicalDiseases(limit);
    }

    @Override
    public Map<String, Object> queryListForYearMedicalDiseases() {
        Map<String, Object> result = new HashMap<>();
        //查询相关机构社区
        List<Map<String,Object>> list_JG = hisTjDjbMapper.queryListForJG();
        result.put("JG",list_JG);
        //查询体检排行前*位的病种名称
        List<Map<String,Object>> list_Diseases = hisTjDjbMapper.queryListForMedicalDiseases(3);
        result.put("BZ",list_Diseases);
        //查询体检年度区间
        Map<String, Object> map_years = new HashMap<>();
        map_years.put("begin",2016);
        map_years.put("end",2017);
        List<Map<String,Object>> list_years = hisTjDjbMapper.queryListForYear(map_years);
        result.put("NF",list_years);
        List<Map<String,Object>> list = null;
        Map<String,Object> map_yearForList = new LinkedHashMap<>();
        //年份
        for(int i=0;i<list_years.size();i++){
            list = new ArrayList<>();

            for(int j=0;j<list_JG.size();j++){//list_years  list_Diseases
                Map<String, Object> map_diseases = new HashMap<>();
                map_diseases.put("years",list_years.get(i).get("years"));
//                map_diseases.put("jbmc",list_Diseases.get(i).get("name"));
                map_diseases.put("jgmc",list_JG.get(j).get("jgmc"));
                //list.addAll(hisTjDjbMapper.queryListForYearMedicalDiseases(map_diseases));


                transform(hisTjDjbMapper.queryListForYearMedicalDiseases(map_diseases));


                list = hisTjDjbMapper.queryListForYearMedicalDiseases(map_diseases);

                map_yearForList.put(list_years.get(i).get("years")+"_"+list_JG.get(j).get("jgmc"),list);
            }
//            map_yearForList.put(list_years.get(i).get("years")+"",list);
//            result.put(list_years.get(i).get("years")+"",list);
        }
        result.put("PX",map_yearForList);
        return result;
    }

    private void transform(List<Map<String,Object>> list){
        System.out.println(list);
        System.out.println(list.size());
    }

    @Override
    public List<Map<String, Object>> queryListForQYJG(String JGMC) {
        return hisTjDjbMapper.queryListForQYJG(JGMC);
    }
}